// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import CustomButton from "../BASE/CButton";
import ComponentBase from "../BASE/ComponentBase";
import Cspine from "../BASE/spineANDgif/Cspine";
import { gif } from "../BASE/spineANDgif/gif";


const { ccclass, property } = cc._decorator;
@ccclass
export default class mouse extends ComponentBase {
    @property(cc.Node)
    gif:cc.Node = null; // 指定的鼠标指针素材
C:CustomButton[]=[];
n:number=0
FDUIs:cc.Node[]=[]
i:number=0
@property(Boolean)
sj=false


  onLoad(){
      //绑定事件

      const isMobile = /Mobile/i.test(navigator.userAgent)
 
      if (isMobile) {
       this.sj=true
      } 












      if (!this.sj) {
      this.node.on(cc.Node.EventType.MOUSE_MOVE,this.mouseFun,this);
      this.node.on(cc.Node.EventType.MOUSE_UP,this.mouseFun,this);
      this.node.on(cc.Node.EventType.MOUSE_MOVE,this.mouseFun,this);
      
        document.body.style.cursor = 'none';
    }
  }
  mouseFun(event){
    let touchLocation = event.getLocation(); // 获取屏幕坐标
let worldPoint = cc.Camera.main.getScreenToWorldPoint(touchLocation); // 转换为世界坐标
      //触摸点的世界坐标
    //  var pos=new cc.Vec3(event.getLocationX(),event.getLocationY(),0);
      //转换为UI坐标
    // pos=this.node.convertToNodeSpaceAR(pos);
      //给要移动的物体赋值
      this.setWorldPos(this.gif,worldPoint)
      //只移动x轴,Y轴同理
      //this.weapon.x=pos.x;
  }
  

    start() {
    if (!this.sj) {
        this.node.on(cc.Node.EventType.MOUSE_DOWN, () => {
            this.gif.getComponent(gif).changeF(3,1)
            
        });
        this.node.on(cc.Node.EventType.MOUSE_UP, (event) => {
            this.gif.getComponent(gif).changeF(2,1)

           if (event.getButton() === 0){
            for(let a of this.FDUIs){
                
                //a.active=false
              //  a.scale=1.2
            }
            this.FDUIs=[]
           } 
           
        });
    }    else{this.gif.active=false}
        


      //  cc.game.frame.requestFullscreen();

      this.gif.zIndex=10000

    }
    




}

